<?php
define("MIN_MONEY", 100000);
define("BAOKIM_REF_LINK","https://www.baokim.vn/thewaytopublishabook");

function get_current_ext_info($uid){
  $result = db_query("SELECT u.* FROM {user_ext} u WHERE u.uid=%d",$uid);
  $record = db_fetch_object($result);
  return $record;
}
function check_transfer_in_progress($uid){
  $sql = "SELECT COUNT(*) FROM {user_ext} ref JOIN {user_tranfer} t ON (ref.last_tran_id = t.tran_id AND ref.uid = t.uid) WHERE t.status = 0 AND ref.uid=%d";
  $count_last_transfer = db_result(db_query($sql, $uid));
  return $count_last_transfer >0;
}
function update_money_by_uid($money,$uid,$pluss,$tran_id){
  if( $pluss ){
    $sql = "UPDATE {user_ext} SET money=money + %d";
  }else {
    $sql = "UPDATE {user_ext} SET money=money - %d";
  }
  if($tran_id){
    $sql.= ',last_tran_id =%d';
  }
  $sql.= " WHERE uid=%d";
  if($tran_id){
    $result = db_query($sql,$money,$tran_id,$uid);
  }else{
    $result = db_query($sql,$money,$uid);
  }
  return $result;
}
function update_leftmoney_by_uid($money,$uid,$pluss){
  if( $pluss ){
    $sql = "UPDATE {user_ext} SET bonus_money=bonus_money + %d";
  }else {
    $sql = "UPDATE {user_ext} SET bonus_money=bonus_money - %d";
  }
  $sql.= " WHERE uid=%d";
  $result = db_query($sql,$money,$uid);
  return $result;
}
function crf_number_format($number,$decimals){
  return number_format($number,$decimals,variable_get("dec_point", ','),variable_get("thousands_sep", '.'));
}
?>